package zk.tool.handler;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import zk.tool.ZKClient;

public abstract class AbstractTreeContextMenuClickHandler<T> implements EventHandler<ActionEvent> {
    private static final Logger log = LoggerFactory.getLogger(AbstractTreeContextMenuClickHandler.class);
    protected TreeView<T> treeView;
    protected ZKClient client;

    public AbstractTreeContextMenuClickHandler(TreeView<T> treeView, ZKClient client) {
        this.treeView = treeView;
        this.client = client;
    }

    @Override
    public void handle(ActionEvent event) {
        if (treeView == null || client == null) {
            return;
        }
        TreeItem<T> selectedItem = treeView.getSelectionModel().getSelectedItem();
        if (selectedItem == null) {
            log.info("selected item is null");
            return;
        }
        handle0(event, selectedItem);
    }

    public abstract void handle0(ActionEvent event, TreeItem<T> selectedItem);

}
